package net.lee.springcloudclient.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import net.lee.springcloudclient.service.ISayHelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;


@Service
public class SayHelloServiceImpl implements ISayHelloService {

    @Autowired
    RestTemplate restTemplate;

    @Override
    @HystrixCommand(fallbackMethod = "hiError")
    public String sayHello(String userName) {
        return restTemplate.getForObject("http://service-hello:18081/hello?username="+userName,String.class);
    }

    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }
}
